home *** CD-ROM | disk | FTP | other *** search
/ C & C++ Multimedia Cyber Classroom / C and C++ Multimedia Cyber Classroom (Prentice Hall) (1998).iso / src / fig09_05.jar / Ch09 / Fig09_05 / Hourly.cpp < prev    next >
C/C++ Source or Header  |  1997-10-27  |  954b  |  31 lines

  1. // Fig. 9.5: hourly.cpp
  2. // Member function definitions for class HourlyWorker
  3. #include <iostream.h>
  4. #include <iomanip.h>
  5. #include "hourly.h"
  6.  
  7. // Constructor for class HourlyWorker
  8. HourlyWorker::HourlyWorker( const char *first, 
  9.                             const char *last,
  10.                             double initHours, double initWage )
  11.    : Employee( first, last )   // call base-class constructor
  12. {
  13.    hours = initHours;  // should validate
  14.    wage = initWage;    // should validate
  15. }
  16.  
  17. // Get the HourlyWorker's pay
  18. double HourlyWorker::getPay() const { return wage * hours; }
  19.  
  20. // Print the HourlyWorker's name and pay
  21. void HourlyWorker::print() const
  22. {
  23.    cout << "HourlyWorker::print() is executing\n\n";
  24.    Employee::print();   // call base-class print function
  25.  
  26.    cout << " is an hourly worker with pay of $"
  27.         << setiosflags( ios::fixed | ios::showpoint )
  28.         << setprecision( 2 ) << getPay() << endl;
  29. }
  30.  
  31.